package com.zsxb.crm.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.github.pagehelper.Page;
import com.zsxb.crm.annotation.AutoFill;
import com.zsxb.crm.annotation.Log;
import com.zsxb.crm.dto.BusinessDTO;
import com.zsxb.crm.dto.BusinessPoolDTO;
import com.zsxb.crm.enumeration.OperationType;
import com.zsxb.crm.pojo.Business;
import com.zsxb.crm.pojo.User;
import io.lettuce.core.dynamic.annotation.Key;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

@Mapper
public interface BusinessMapper extends BaseMapper<Business> {

    Page<Business> pageQuery(BusinessDTO businessDTO);
    //根据id查询商机
    Business getById(Long businessId);

    @Select("select * from tb_business")
    List<Business> findAll();


    @Update("update tb_business set status = #{status},remark=#{remark},back_reasons = #{backReasons},owner=#{owner},owner_time=#{ownerTime} where id = #{id}")
    @AutoFill(OperationType.UPDATE)
    void backSea(Business business);

    Page<Business> poolPageQuery(BusinessPoolDTO businessPoolDTO);


    Integer getBusinessNum(User user);
    Integer getBusinessNum(Long id);

    @AutoFill(OperationType.UPDATE)
    void updateByUserId(Long isUserId, Long outUserId);

    Integer countWithUserId(Long userId);

    List<Business> selectByBusinessIds(List<Long> ids);
    //分配商机

    void assign(Business business);
}
